package C031;

import java.util.HashMap;

/**
 * ClassName: Code03_Near2power
 * Package: C031
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/12/27 16:21
 * @Version 1.0
 * @Since 1.0
 */
public class Code03_Near2power {

    public static void main(String[] args) {
        System.out.println(near2power(-1));
        System.out.println(near2power(4));
        System.out.println(near2power(12));
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>(4);
        System.out.println();
    }

    public static int near2power(int num) {
        if(num <= 0) {
            return 0;
        }
        num --;
        num |= num >> 1;
        num |= num >> 2;
        num |= num >> 4;
        num |= num >> 8;
        num |= num >> 16;
        num ++;
        return num;
    }
}
